package com.cybersapien.comng.object.weapon.normalgunweapon.action;

import java.util.ArrayList;
import java.util.List;

import com.cybersapien.comng.engine.action.IAction;
import com.cybersapien.comng.engine.action.IActionActor;
import com.cybersapien.comng.engine.action.IActionObject;
import com.cybersapien.comng.engine.action.IActionTarget;
import com.cybersapien.comng.engine.entity.EntityHelper;
import com.cybersapien.comng.engine.event.EventHelper;
import com.cybersapien.comng.engine.event.engine.IEventEngine;
import com.cybersapien.comng.object.weapon.action.AttackAction;
import com.cybersapien.comng.object.weapon.normalgunweapon.event.NormalGunAttackFailure;
import com.cybersapien.comng.object.weapon.normalgunweapon.event.NormalGunAttackSuccess;

public class NormalGunAttackAction extends AttackAction implements IAction {

	public void doAction(ActionParams parameters) {
		String idActor = (String) parameters.get("ID_ACTOR");
		String idTarget = (String) parameters.get("ID_TARGET");
		String idWeapon = (String) parameters.get("ID_WEAPON");

		IActionActor actor = EntityHelper.getEntityByIdByType(idActor, IActionActor.class);
		IActionTarget target = EntityHelper.getEntityByIdByType(idTarget, IActionTarget.class);
		IActionObject weapon = EntityHelper.getEntityByIdByType(idWeapon, IActionObject.class);

		Result result = this.testAction(parameters);

		List<IEventEngine> events = new ArrayList();

		switch (result) {
		case EPIC_SUCCESS:
		case SUCCESS:
			events.add(new NormalGunAttackSuccess());
			break;
		case EPIC_FAILURE:
		case FAILURE:
			events.add(new NormalGunAttackFailure());
			break;

		}

		for (IEventEngine event : events) {
			EventHelper.addEngineEvent(event);
		}
	}

	@Override
	public boolean validateAction(ActionParams parameters) {
		return true;
	}

	@Override
	public Result testAction(ActionParams parameters) {
		return Result.SUCCESS;
	}

}
